package com.crl.ssc.dic.service;

import com.cars.util.global.GlobalOperaCode;
import com.cars.util.list.ListUtils;
import com.crl.ssc.dic.dao.DicProvinceDao;
import com.crl.ssc.dic.dto.DicProvinceDTO;
import com.crl.ssc.dic.model.DicProvince;
import com.crl.ssc.dic.vo.DicProvinceSearchVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @description: 省份字典管理Service
 * @author: 孔垂云
 * @version: 1.0
 * @date: 2020/7/21 13:16
 */
@Service
public class DicProvinceService {
    @Autowired
    private DicProvinceDao dicProvinceDao;

    /**
     * 增加省份字典
     *
     * @param dicProvinceDTO
     * @return
     */
    public int add(DicProvinceDTO dicProvinceDTO) {
        DicProvince dicProvince = new DicProvince();
        BeanUtils.copyProperties(dicProvinceDTO, dicProvince);
        return dicProvinceDao.add(dicProvince);
    }

    /**
     * 修改省份字典
     *
     * @param dicProvinceDTO
     * @return
     */
    public int update(DicProvinceDTO dicProvinceDTO) {
        DicProvince dicProvince = new DicProvince();
        BeanUtils.copyProperties(dicProvinceDTO, dicProvince);
        return dicProvinceDao.update(dicProvince);
    }

    /**
     * 删除省份字典
     *
     * @param provinceCode
     * @return
     */
    public int delete(String provinceCode) {
        DicProvince dicProvince = dicProvinceDao.get(provinceCode);
        if (dicProvince == null) {
            return GlobalOperaCode.OPERA_NOT_EXIST;
        } else {
            return dicProvinceDao.delete(provinceCode);
        }
    }


    /**
     * 省份字典列表
     *
     * @param dicProvinceSearchVO
     * @return
     */
    public List<DicProvinceDTO> list(DicProvinceSearchVO dicProvinceSearchVO) {
        List<DicProvince> list = dicProvinceDao.list(dicProvinceSearchVO);
        List<DicProvinceDTO> listResult = ListUtils.copyList(list, DicProvinceDTO.class);
        return listResult;
    }

    /**
     * 查询省份字典记录条数
     *
     * @param dicProvinceSearchVO
     * @return
     */
    public int count(DicProvinceSearchVO dicProvinceSearchVO) {
        return dicProvinceDao.count(dicProvinceSearchVO);
    }

    /**
     * 获取单个省份字典
     *
     * @param provinceCode
     * @return
     */
    public DicProvinceDTO get(String provinceCode) {
        DicProvince dicProvince = dicProvinceDao.get(provinceCode);
        DicProvinceDTO dicProvinceDTO = new DicProvinceDTO();
        BeanUtils.copyProperties(dicProvince, dicProvinceDTO);
        return dicProvinceDTO;
    }

}
